<extend name="common:commonTemplate" />
<block name="main_content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">会议管理</a> <a class="current" href="#">投票查询</a>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>搜索条件</h5>
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate"
							name="basic_validate" action="#" method="post"
							class="form-horizontal">
							<div class="control-group">
								<label class="control-label">投票主题:</label>
								<div class="controls">
									<input type="text" id="vote_name" name="vote_name"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">开始时间:</label>
								<div class="controls">
									<input id="start_time" name="start_time" class="date_controller" onclick="laydate({elem: '#start_time', istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
								</div>
							</div>
							
							<div class="control-group">
								<label class="control-label">结束时间:</label>
								<div class="controls">
									<input id="end_time" name="end_time" class="date_controller" onclick="laydate({elem: '#end_time', istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
								</div>
							</div>
							
							
							
							<div class="form-actions">
								<input id="btn_vote_search" type="button" class="btn btn-success" value="搜索">
								<a target="_blank" href="/vote/addvotePage" style="background:red" class="btn btn-success">新增</a>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	
	<div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>搜索结果</h5>
          </div>
          <div class="widget-content nopadding">
            <table id="search_result"  page_index="1" class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th style="min-width: 40px">投票主题</th>
                  <th width="120px">开始时间</th>
                  <th width="120px">结束时间</th>
                  <th style="min-width: 200px">备注</th>
                  <th width="80px">操作</th>
                </tr>
              </thead>
              <tbody>
              </tbody>
            </table>
          </div>
      </div>
         <div id="paging"
                         class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
                        <div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers"
                             id="DataTables_Table_0_paginate">
                            <a page_index="1"
                               class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_first">首页</a>
                            <a class="previous fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_previous">上页</a>
                            <span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span
                                    id="total_page">0</span></span>
                            <a class="next fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_next">下页</a>
                            <a class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_last">末页</a>
       			<span>
        			<span><input type="text" id="page_input" style="width: 20px; vertical-align: top; height: 16px;" class="ui-state-default"></span>

        			<a class="fg-button ui-button ui-state-default" id="page_jump" tabindex="0">跳转</a>
       			</span>
                        </div>
       </div>
    </div>
  </div>

</div>
</div>
</block>

<block name="js_content">
<script src="/Public/js/common.js?v=16"></script>
<script src="/Public/js/laydate/laydate.js"></script> 
<script src="/Public/assets/js/layer/layer.js" type="text/javascript"></script>
<script>

VotePage = {
		'BindEvent': function(){
			$('#btn_vote_search').bind('click', function(){
				 var page_index = 1;
				 VotePage.Search(page_index);
			});
			$('#page_jump').bind('click', function(){
				 var page_index = $('#page_input').val();
				 var total_page = $('#total_page').text();
				 var curr_page = $('#curr_page_index').text();
				 if (page_index == ''||page_index == undefined||page_index == null) {
	                    page_index = curr_page;
	                }
				 if(parseInt(page_index) <= 0 || parseInt(page_index) > parseInt(total_page)  ){
					 page_index =1;
				 }
				 VotePage.Search(page_index);
			});
			 $(".first,.previous,.last,.next").bind('click', function () {
	                if ($(this).hasClass('ui-state-disabled')) {
	                    return false;
	                }

	                var page_index = $(this).attr('page_index');
	                if (page_index == undefined) {
	                    page_index = 1;
	                }
	                //page_index = 1;
	                VotePage.Search(page_index);
	            });
		},
		'Search': function (page_index) {
            var condition = $("#basic_validate").serialize();
            condition += "&pageSize=20&index="+page_index;

            $.ajax({
                type: 'post',
                url: '/AjaxService/center/vote/queryvotelist',
                data: condition,
                dataType: 'json',
                success: function (data) {
                	VotePage.BindTable(data.Result, page_index);
                	CommonPage.SetPageIndex(data.Result.totalPage, data.Result.totalCount, page_index);
                },
                error: function (e, err_name, err_text) {
                    alert(err_text);
                }
            });

        },
		'BindTable': function(result,page_index){
			lst_vote = result.datas;
			
			if(lst_vote.length == 0){	
				
				$('#search_result tbody').html('');
				var msg ="<tr><td colspan='16' style='text-align:center'>暂无数据!</td></tr>";				
				$('#search_result tbody').append(msg);	
				return;
			};
			var html = '';
			for(var index in lst_vote){
				var vote_en = lst_vote[index];
				var tr_html = "<tr>";
				tr_html += "<td>" + CommonPage.convertNull(vote_en.vote_name)+"</td>";
				tr_html += "<td>" + CommonPage.convertNull(vote_en.start_time) + "</td>";
				tr_html += "<td>" + CommonPage.convertNull(vote_en.end_time) + "</td>";
				tr_html += "<td>" + CommonPage.convertNull(vote_en.remark1) + "</td>";
				tr_html += "<td class='taskOptions' style='text-align: center;'>";
				tr_html += '<a data-original-title="查看详情" target="_blank" class="tip-top" href="/vote/editVotePage?vote_id=' +vote_en.vote_id +'"><i class="icon-pencil"></i></a>';
				tr_html += '&nbsp;&nbsp;&nbsp;&nbsp;';
				tr_html += '<a data-original-title="二维码" class="tip-top" href="javascript:void(0);" onclick="VotePage.showQrCode('+ '\'' + vote_en.vote_id + '\'' +')" ><i class="icon-qrcode"></i></a>';
				tr_html += '&nbsp;&nbsp;&nbsp;&nbsp;';
				tr_html += '<a data-original-title="图表" target="_blank" class="tip-top" href="/vote/voteCharts?vote_id=' +vote_en.vote_id +'"><i class="icon-bar-chart"></i></a>';
				tr_html += "</td>";
				/* tr_html += "<td style='text-align: center;'>"+"<a style='color:blue;' href='/vote/editVotePage?vote_id="+ vote_en.vote_id + "'>查看详情</a></td>" */
				tr_html += "</tr>";
				html += tr_html;
			} 
			$('#search_result tbody').html('');
			$('#search_result tbody').append(html);
			$('#search_result').attr('page_index', page_index);
			$('.tip-top').tooltip({ placement: 'top' });
		},
		'showQrCode' : function(vote_id){
            layer.open({
                type: 2,
                title: '投票二维码',
                fix: true,
                shadeClose: true,
                maxmin: false,
                area: ['380px', '410px'],
                content: '/vote/voteQrCode?vote_id='+vote_id
            });
        },
		'ConvertOptions': function(type,obj){
			var display = '【转换失败:'+obj+'】';
			$.each(VotePage[type], function(key, value){
			  if(key == obj){
				  display = value;
				  return false;
			  }
			});
			return display;
		}
};


$(document).ready(function(){
	VotePage.BindEvent();
});

</script>
</block>